package com.example.demo.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.example.demo.entity.Person;
import com.example.demo.service.PersonService;

@Controller
@RequestMapping("hello")
public class HelloController {

	@RequestMapping("abc")
	@ResponseBody
	public String hello() {
		return "<h1>这是我的第一个SpringMvc</h1>";
	}
	
	@Resource
	private PersonService personService;
	
	
	@RequestMapping("insert")
	@ResponseBody
	public Person insert(Person p) {
		return personService.insert(p);
	}
	
	@RequestMapping("del")
	@ResponseBody
	public String delete(Integer id) {
		personService.deleteById(id);
		return "<h1>删除成功</h1>";
	}
	@RequestMapping("all")
	@ResponseBody
	public Object findAll() {
		return personService.findAll();
	}
	@RequestMapping("update")
	@ResponseBody
	public Object update(Integer id, String name, Character sex) {
		Person person = personService.findOne(id);
		person.setName(name);
		person.setSex(sex);
		return personService.update(person);
	}
	
}
